import { notFound } from "next/navigation";
// import { redirect } from "next/navigation";

// 为了呈现 error.tsx 的作用，设计一个随机数，当productId是1的时候显示error的内容
const randomProductId = (count: number) => {
    return Math.floor(Math.random() * count);
}

export default async function ReviewDetail({ params }: { params: Promise<{ productId: string, reviewId: string }> }) {

    const { productId, reviewId } = await params;
    const randomId = randomProductId(2);
    if(randomId === 1){
        // 模拟一个错误
        throw new Error("Something went wrong!");
    }
    if (parseInt(reviewId) > 1000) {
        return (
            notFound()
            // redirect去products页面
            // redirect("/products")
        )
    }
    return (
        <h1>Review {reviewId} for product {productId}</h1>
    )
}